var loadingDiv = '<div id="loadingDiv" class="ui-state-highlight"><em>LOADING...</em></div>';
var loadingOption = "<option value=''>Loading...</option>";

var view = function(viewName) {
	return $("#"+viewName+"Container");
}

var route = function(userArgs) {
	var args = {
		namespace: "CFmaker",
		control: {
			selector: "",		// jQuery selector for the control that triggers the event
			event: "click",		// the name of the event we are listening for, must be a valid jQuery event-name
		}
		com: {					// controller call details
			selector: "",		// jQuery selector for the source of the data
								// extraneous data should be stored in markup attributes
			method: "",			// if the name is blank (default) no call is made
			args: { }
		},
		view: {					// view update details
			selector: "",		// jQuery selector for the container to be updated
			name: "",			// name of the view to draw in the target
			args: { }
		},
		success: function() { },// callback which fires after completion of everything 
		error: function() { }
	}
	
	$.extend(args, userArgs);

	$(args.control.selector).bind(args.control.event, function() {
		// controller call
		if (args.com.selector.length) {
			$(args.com.selector).com(method, args);
		} else {
			$.getJSON(controllerName, function(data) {
				$.data(controllerName, data);
			});
		}
		
		// view update
		if (args.view.selector.length) {
			$(args.view.selector).display(args.view.name, arg.view.args);
		} else {
			if (!args.view.name.length) {
				log("Invalid selector for router:view " + args.view.name);
			} else {
				log("Invalid view name for router:view " + args.view.name);
			}
		}
		
		// callback
		if ($.isFunction(args.success))
			args.success();
	});

	// helper fn for console logging
	// set $.fn.ajaxSubmit.debug to true to enable debug logging
	// borrowed from jQuery.form ... trying to stay with convention
	function log() {
		if ($.fn.ajaxSubmit.debug && window.console && window.console.log)
			window.console.log('[jquery.CFmaker] ' + Array.prototype.join.call(arguments,''));
	};
}